﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stateless
{
    public partial class StateMachine<TState, TTrigger, TData0>
    {
        internal class DynamicTriggerBehaviour : TriggerBehaviour
        {
            readonly Func<TData0, TState> _destination;
            readonly Func<TData0, bool> _guard;

            public DynamicTriggerBehaviour(TTrigger trigger, Func<TData0, TState> destination, Func<TData0, bool> guard)
                : base(trigger)
            {
                _destination = Enforce.ArgumentNotNull(destination, "destination");
                _guard = guard;
            }

            public override bool ResultsInTransitionFrom(TState source, TData0 args, out TState destination)
            {
                destination = _destination(args);
                return true;
            }

            public override bool Guard(TData0 args)
            {
                return _guard(args);
            }
        }
    }
}
